package com.zjb.demo.common.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 庄佳彬
 * @since 2023/12/24 21:43
 */
public class IPUtils {

    /**
     * 获取本机主机名
     *
     * @return 本机主机名
     */
    public static String getHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException ignored) {
        }
        return "未知";
    }


    /**
     * 获取主机的IP地址
     *
     * @return 主机的IP地址
     */
    public static String getHostIp() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException ignored) {
        }
        return "127.0.0.1";
    }

}
